GSP-001 Creating a Virtual Machine

2017 9 24일 일요일

오전 12:46

링크: https://google.qwiklabs.com/focuses/5318

 

Google Cloud Platform Console (GCS) 또는, gcloud CLI로 다양한 VM instance를 만들어보자.

 

시작하기전, 첫시간이니

 

1) 구글 계정

2) 계정 밑에 여러 개의 project (=A회사 프로젝트, B회사 프로젝트, 개인 프로젝트)

- 프로젝트마다 Billing

3) 밑에 다양한 GCP의 기능(?)

잡다한 것들

RPI 
Cloud Launcher 
Billing 
APIs & services 
Support 
IAM & admin 
Getting started

 

컴퓨터

COMPUTE 
App Engine 
Compute Engine 
Container Engine 
Cloud Functions

 

저장장치

STORAGE 
Bigtable 
Datastore 
Storage 
SQL 
Spanner

 

네트워킹

NETWORKING 
VPC network 
Network services 
Interconnect

 

모니터링

STACKDRIVER 
o 
Monitoring 
Debug 
Trace 
Logging 
Error Reporting

 

도구들

TOOLS 
(O) 
Container Registry 
Source Repositories 
Deployment Manager 
Endpoints

 

빅데이터

DATA 
BigQuery 
Pub/Sub 
Dataproc 
Dataflow 
ML Engine 
Genomics 
10T Core 
Dataprep

 

 

What you'll do

 

Create a virtual machine with the Google Cloud Platform Console

- GUI 에서 (아마도) API를 통해 VM 만들기

Create a virtual machine with gcloud command line

- CLI 에서 SDK를 통해 이미 설치되어 있는 gcloud SDK를 통해 CLI 를 거쳐 (아마도) API VM 만들기

- 셀에서 gcloud --version 쳐보자

Deploy a web server and connect it to a virtual machine

- nginx (엔진엑쓰) 웹서버 설치해보기

 

VM instance 생성

 

랩에서 시키는 옵션대로 VM instance를 생성해보자.

그리고 SSH 창을 열자

- 지금 우리는 SSH (=Secure Shell = 텔넷보다 보안이 좋다) 를 통해서

- 우리가 만든 VM에 들어간 것이다

* google cloud shell 에서 gcloud compute ssh [VM이름]을 쳐도 된다

 

Name O 
gcelab 
Zone 
us-centralV: 
Machine type 
1 vCPU 
$25.97 per month estimated 
Effective hourly rate 30.036 (730 hours per month) 
Details 
3.75 GB memory 
Upgrade mr account to create instances with up to 64 cores 
Boot disk 
New 10 GB SSD persistent disk 
Image 
Debian GNU/Linux 8 (jessie) 
Identity and API access 
Service account 
Compute Engine default service account 
Access scopes 
• Allow default access 
Allow full access to all Cloud APIs 
Set access for each API 
Firewall 
Customize 
Change 
Add and firewall pules to allow specific network traffic from the Internet 
91 Allow HTTPtratfic 
91 Allow HTTPS 
Management, disks, networking, SSH keys

 

NGINX web server 인스톨하기

 

sudo su -

sudO SLI, 
sudO 
sudO 
su -자이점 
현재 계정에서 다른 계정의 권한만 빌림 
다른 계정으로 로그이 
다른 계정으로 전환 
다른 계정으로 전환 + 그 계정의 환경변수 적용

참고링크: https://askubuntu.com/questions/376199/sudo-su-vs-sudo-i-vs-sudo-bin-bash-when-does-it-matter-which-is-used

To explain this you need to know what the programs do: 
su - The command su is used to switch to another user (s witch u ser), but you can also switch 
o e root user by invoking the command with no parameter su asks you for the password of the 
user to switch, after typing the password you switched to the user's environment. 
sudo is meant to run a single command with root privileges. But unlike su it prompts you 
s udo 
or e password of the current user This user must be in the sudoers file (or a group that IS in the 
sudoers file) By default, Ubuntu "remembers" your password for 15 minutes; so that you don't have 
to type your password every time 
bash A text-interface to interact with the computer It's important to understand the difference 
between login, non-login, interactive and non-interactive shells: 
• login shell: A login shell logs you into the system as a specified user, necessary for this is a 
username and password. When you hit ctrl + alt + Fl to login into a virtual terminal you get 
after successful login a login shell. 
• non-login shell: A shell that is executed without logging in, necessary for this is a currently 
logged-in user. When you open a graphic terminal in gnome it is a non-login shell 
• interactive shell: A shell (login or non-login) where you can interactively type or interrupt 
commands. For example a gnome terminal 
• non-interactive shell: A (sub)shell that is probably run from an automated process. You will see 
neither input nor output 
sudo su Calls sudo with the command su _ Bash is called as interactive non-login shell So bash 
on y executes . bashrc You can see that after switching to root you are still in the same directory: 
sudo su 
root@host : / home/ user#

 

his time it is a login shell, so /etc/profile , . profile and . bashrc are executed 
sudo su - 
and you will find yourself in root's home directory with root's environment 
sudo -i It is nearly the same as sudo su - The -i (simulate initial login) option runs the shell 
specified by the password database entry of the target user as a login shell This means that login 
specific resource files such as . profile , . bashrc or . login will be read and executed by the 
shell. 
means that you call sudo with the command /bin/bash . /bin/bash is 
started as non-login shell so all the dot-files are not executed but bash itself reads . bashrc of the 
calling user Your environment stays the same. Your home will not be root's home. So you are root, 
but in the environment of the calling user. 
sudo -s reads the *SHELL variable and executes the content If *SHELL contains /bin/bash it 
invokes sudo /bin/bash (see above). 
Check: To check if you are in a login shell or not (works only in bash because shopt is a builtin 
command): 
shopt -q login_shell echo 'Login shell' I 
echo 'No login shell

 

 

apt-get update

 

apt-get apt-get update의 개념 이해하기 https://blog.outsider.ne.kr/346

update는 사용가능한 패키지들과 버전들의 리스트를 업데이트

upgrade는 내 리눅스내의 패키지들을 실제로 최신버전으로 업그레이드

 

apt-get install nginx -y

- "-y" (무조건 yes)

 

ps auwx | grep nginx

- ps auwx 로 리스트를 보는데

- 그 중에서 nginx 만을 챙겨보려는 듯

 

브라우저로 열기

- 분명 https 도 허용했는데 http만 됨 - 앗 또 이렇게 되네 @_@

- 추후 확인 필요

- 끄응~ 당연한 것이었다.

- https가 되려면 일단 웹서버에서 관련 설정을 해야하고 (=nginx)

- firewall 도 설정이 되어있어야 하고

- 보통 target_tag를 설정하고

- target_tag가 동일한 VM등에 그 firewall rule이 적용된다.

VPC network 
VPC networks 
External IP addresses 
Firewall rules 
Routes 
VPC network peering 
Shared vpc 
Create a firewall rule 
Description (Optionan 
Network O 
default 
Priority 
Priority can be O - 65535 Check priority of other firewall rules 
1000 
Direction of traffc 
• Ingress 
Egress 
Action on match 
• Allow 
Deny 
Targets 
Specified target tags 
Target tags 
Source filter 
IP ranges

 

Q 
Google Cloud Platform 
Compute Engine 
VM instances 
Instance groups 
Instance templates 
Disks 
Snapshots 
Images 
Committed use discounts 
Metadata 
Health checks 
Zones 
My Project 
VM instance details 
Firewalls 
Allow HTTP traffic 
Allow HTTPS traffic 
Network tags 
Boot disk and local disks 
Name 
jhs-vml 
Delete boot disk when instance is deleted 
(Option-Il 
Additional disks 
+ Add item 
Availability policies

 

- 인증서도 필요하다

 

gcloud VM instance 생성

 

gcloud compute instances create [VM이름] --zone us-central1-c

--zone us-central1-c 라고?

 

default region 이나 zone을 설정할 수도 있는데

- local PC에 설정한건 유지되지만

- Google Cloud Shell 에 설정한건 재연결할땐 사라져있다

Note: You can set the default region and zones that gcloud uses if you are 
always working within one region/zone and you don't want to append the 
zone flag every time. Do this by running these commands : 
gcloud config set compute/ zone . 
gcloud config set compute/ region

 

 

SDK에서 실행하고 아래 보여주기

- gcloud components list

- gcloud components update

 

 

의외로 OS가 뭔지 웹콘솔에서는 알려주지 않는듯하다.

uname -a 명령 사용해서 볼 수 있다.

 

gcloud compute instances create --help 를 통해 default 값 확인가능

- 다양한 머신타입 링크: https://cloud.google.com/compute/docs/machine-types#predefined_machine_types

 

gcloud compute ssh [VM이름]

- 이런 단순한 명령만으로도 VM instance SSH로 접속이 된다

 

정리

Google Compute Engine (GCE) Infrastructure-as-a-Service (IaaS) 이다.

여기다가 기존의 서버 구성요소들을 가져올 수 있다.

- server infrastructure

- load balancers

- network topology

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Microsoft OneNote 2016에서 작성